package com.ohuang.onlytest.floating;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;

public class TestFloatingView {

    /**
     * 当前activity显示悬浮窗
     * @param activity
     * @param viewBuild
     */
    public static void showView(Activity activity,ViewBuild viewBuild){
        FloatingMagnetHelper floatingMagnetHelper = new FloatingMagnetHelper(activity,viewBuild);
        floatingMagnetHelper.show();
    }

    /**
     * 所有activity全局显示悬浮窗
     * @param application
     * @param viewBuild
     */
    public static void showGlobalView(Application application, ViewBuild viewBuild){
        FloatingMagnetManager floatingMagnetHelper = new FloatingMagnetManager(viewBuild);
        application.registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
                floatingMagnetHelper.attach(activity);
            }

            @Override
            public void onActivityStarted(Activity activity) {

            }

            @Override
            public void onActivityResumed(Activity activity) {
                floatingMagnetHelper.show( activity);
            }

            @Override
            public void onActivityPaused(Activity activity) {
                floatingMagnetHelper.hide( activity);
            }

            @Override
            public void onActivityStopped(Activity activity) {

            }

            @Override
            public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

            }

            @Override
            public void onActivityDestroyed(Activity activity) {
                floatingMagnetHelper.onDestroy(activity);
            }
        });

    }
}
